package fr.upmc.i3s.upmcontact.tools;

import java.io.File;
import java.util.List;

import android.util.Log;

import fr.upmc.i3s.upmcontact.Constants;

public class FileUtils implements Constants {
	
	private static final String TAG = "FileUtils";
	
	public static void createDirectory(String path) {
		File f = new File(path);
		f.mkdir();
	}
	
	public static boolean rmAllFilesInDirectoryExcept(String directory, List<String> exceptedFiles) {
		File dir = new File(directory);
		if(dir.isDirectory()) {
			Log.d(TAG, "rmAllFilesInDirectoryExcept.directory="+directory+", exceptedFiles.size()="+exceptedFiles.size());
			String[] files = dir.list();
			for(String f : files) {
				boolean shouldBeDeleted = true;
				for(String ef : exceptedFiles) {
					if(ef.contains(f)) { 
						shouldBeDeleted = false;
						break;
					}
				}
				if(shouldBeDeleted) {
					Log.d(TAG, "local file will be deleted : "+directory+f);
					File fDel = new File(directory+f);
					fDel.delete();
				}
			}
			return true;
		} 
		return false;
	}

}
